package com.fwtai.controller.web;

import com.fwtai.bean.PageFormData;
import com.fwtai.service.core.AreaService;
import com.fwtai.service.web.PartnerAreaService;
import com.fwtai.tool.ToolClient;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * 合伙|代理的特殊区域控制层|路由层
 * @作者 田应平
 * @版本 v1.0
 * @QQ号码 444141300
 * @创建日期 2023-07-22 14:36:48
 * @官网 <url>http://www.fwtai.com</url>
*/
@RestController
@RequestMapping("/partnerArea")
public class PartnerAreaController{

  private final PartnerAreaService partnerAreaService;

  private final AreaService areaService;

  public PartnerAreaController(final PartnerAreaService partnerAreaService,final AreaService areaService){
    this.partnerAreaService = partnerAreaService;
    this.areaService = areaService;
  }

  /**添加*/
  @PreAuthorize("hasAuthority('area_proxy_btn_add')")
  @PostMapping("/add")
  public void add(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(partnerAreaService.add(request),response);
  }

  /**行内编辑*/
  @PreAuthorize("hasAuthority('area_proxy_row_edit')")
  @PostMapping("/edit")
  public void edit(final Long areaId,final Integer level,final HttpServletResponse response){
    ToolClient.responseJson(partnerAreaService.edit(areaId,level),response);
  }

  /**根据id查询对应的数据*/
  @PreAuthorize("hasAuthority('area_proxy_row_queryById')")
  @GetMapping("/queryById")
  public void queryById(final Long id,final HttpServletResponse response){
    ToolClient.responseJson(partnerAreaService.queryById(id),response);
  }

  /**启禁用*/
  @PreAuthorize("hasAuthority('area_proxy_row_delById')")
  @PostMapping("/delById")
  public void delById(final Long areaId,final Long kid,final Integer disable,final HttpServletResponse response){
    ToolClient.responseJson(partnerAreaService.delById(areaId,kid,disable),response);
  }

  /**获取数据*/
  @PreAuthorize("hasAuthority('area_proxy_btn_listData')")
  @GetMapping("/listData")
  public void listData(final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(partnerAreaService.listData(new PageFormData(request)),response);
  }

  /**搜索用户用于绑定*/
  @PreAuthorize("hasAuthority('area_proxy_btn_listUser')")
  @GetMapping("/getUserList")
  public void getUserList(final String word,final HttpServletResponse response){
    ToolClient.responseJson(partnerAreaService.getUserList(word),response);
  }

  /**区域绑定用户*/
  @PreAuthorize("hasAuthority('area_proxy_row_addUser')")
  @PostMapping("/addUser")
  public void addUser(final Integer level,final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(partnerAreaService.addUser(request,level),response);
  }

  @PreAuthorize("hasAuthority('area_proxy_row_listArea')")//获取区域信息
  @GetMapping("/getListArea")
  public void getListArea(final String pid,final String selected,final HttpServletRequest request,final HttpServletResponse response){
    ToolClient.responseJson(areaService.getListArea(pid,selected,request),response);
  }
}